:: Set encodeing to UTF-8 for console
@CHCP 65001
:: MSVC(Visual Studoi 2015)编译 simplemq-cpp 脚本
:: 可选参数:
::   /RELEASE          - 编译Release项目
echo off 
SETLOCAL
echo make simplemq Visual Studio project
where cmake
if errorlevel 1 (
	echo cmake NOT FOUND.
	exit /B -1
)
echo cmake found
where conan
if errorlevel 1 (
	ECHO conan NOT FOUND.
	exit /B -1
)
ECHO conan found
where python
if errorlevel 1 (
	ECHO python NOT FOUND.
	exit /B -1
)
ECHO python found
:: 检查Python 版本,要求Python 3
python --version | findstr /C:"Python 3"
if errorlevel 1 (
	ECHO python 3 required.
	exit /B -1
)
set sh_folder=%~dp0
rem 删除最后的 '\'
set sh_folder=%sh_folder:~0,-1%

SET BUILD_TYPE=Debug

SET msvc_runtime=MD

:: parse command arguments
:loop
IF x%1 == x GOTO :pare_end
IF /I "%1" == "/RELEASE"    SET OPT_BUILD=1 && SET BUILD_TYPE=Release

SHIFT
GOTO :loop
:pare_end

IF /I "%BUILD_TYPE%" == "DEBUG"    SET msvc_runtime=%msvc_runtime%d


pushd %sh_folder%

if exist project.msvc rmdir project.msvc /s/q
mkdir project.msvc
pushd project.msvc

:: conan 安装依赖库
conan install ^
	--requires common_source_cpp/1.0.1^
	--requires paho-mqtt-cpp/1.2.0 ^
	--requires cpp_redis/master ^
	-s arch=x86_64 ^
	-s build_type=%BUILD_TYPE% ^
	-s compiler="Visual Studio" ^
	-s compiler.runtime=%msvc_runtime% ^
	-g CMakeDeps ^
	-g CMakeToolchain ^
	%CONAN_REMOTE_REPO% ^
	--build missing || EXIT /B

echo creating x86_64 Project for Visual Studio ...

cmake .. -A x64 -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
	-DCMAKE_INSTALL_PREFIX=..\release\simplemq_windows_vc_x86-64  ^
	-DCMAKE_TOOLCHAIN_FILE=./conan_toolchain.cmake 

popd
popd
ENDLOCAL